<template>
	<div class="hy-container">
		<HyTable
			:searchFields="searchFields"
			:searchConfig="searchConfig"
			:searchDefault="searchDefault"
			:tableConfig="tableConfig"
			:tableColumns="tableColumns"
			ref="hyTableRef"
		>
			<template #tableHeader>
				<el-button type="primary" @click="handleOperate('add')" icon="Plus">新增</el-button>
			</template>
			<template #operation>
				<el-table-column fixed="right" label="操作" width="205">
					<template #default="{ row }">
						<div class="flex items-center w-full justify-between">
							<el-button text type="primary" icon="View" @click="handleOperate('view', row)">查看</el-button>
							<el-button text type="primary" icon="Edit" @click="handleOperate('edit', row)">编辑</el-button>
							<el-button text type="danger" icon="Delete" @click="handleOperate('delete', row)">删除</el-button>
						</div>
					</template>
				</el-table-column>
			</template>
		</HyTable>
	</div>
</template>

<script lang="ts" setup>
import HyTable from '/@/components/HyTable/index.vue';
import { meetingPageApi, meetingDeleteApi } from '/@/api/expertDatabase/extract';
import { ElMessageBox, ElLoading } from 'element-plus';
const tableColumns = computed(() => {
	return [
		{ prop: 'meetingName', label: '会议名称' },
		{ prop: 'reviewAppStr', label: '评审应用', width: 300 },
		{ prop: 'reviewAddress', label: '评审地点', width: 300 },
		{ prop: 'contactPerson', label: '联系人', width: 300 },
		{ prop: 'reviewTime', label: '评审时间', width: 200 },
		{ prop: 'contactInformation', label: '联系方式', width: 200 },
	];
});
const tableConfig = computed(() => {
	return {
		request: meetingPageApi,
	};
});
// 配置搜索
const searchFields = computed(() => {
	return {
		keyword: {
			type: 'input',
			label: '关键字',
		},
	};
});
const searchConfig = computed(() => {
	return {
		labelWidth: '120px',
		type: 'search',
		title: '专家和机构抽取',
		show: true,
	};
});
const searchDefault = ref({});
//操作
const router = useRouter();
const hyTableRef = ref();
const handleOperate = (operateType: string, row?: any) => {
	if (operateType === 'delete') {
		ElMessageBox.confirm('是否确定删除?', '操作确认', {
			confirmButtonText: '确认',
			cancelButtonText: '取消',
			type: 'warning',
		}).then(() => {
			const loading = ElLoading.service({
				lock: true,
				text: '删除中...',
			});
			meetingDeleteApi({ id: row.id })
				.then(() => {
					hyTableRef.value.handleSearch();
				})
				.finally(() => {
					loading.close();
				});
		});
	} else {
		router.push({
			path: '/expertDatabase/extract/operate',
			query: {
				operateType,
				id: row?.id || '',
			},
		});
	}
};
</script>
<style scoped lang="scss"></style>
